import React, { useEffect, useState } from 'react';
import { Empty, Table } from 'antd';
import Cls from 'classnames';
import { getApplyPackTableColumns } from '../mconfig';
import { ApplyManageAPI } from '../common/type';

/**
 * @UpdatePackList 步骤条第三步采购内容表格组件
 * @param packList 表格数据
 * @param jumpSource 跳转寻源
 * @returns
 */
export const UpdatePackView: React.FC<ApplyManageAPI.IUpdatePackView> = ({ formName, packList, jumpSource }) => {
  /** 表格数据 */
  const [dataSource, setDataSource] = useState<Record<string, any>[]>([]);

  /** 查询申请详情，并回显数据 */
  useEffect(() => {
    if (packList?.length > 0) setDataSource(packList);
  }, [packList]);

  return (
    <div className={Cls(`list-table`, `UpdatePackTable`)}>
      {dataSource.length > 0 ? (
        <Table
          bordered
          size="small"
          dataSource={dataSource}
          columns={getApplyPackTableColumns({ dataSource, jumpSource })}
          rowKey={'id'}
          pagination={false}
          scroll={{ x: 'true', y: 'true' }}
        />
      ) : (
        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
      )}
    </div>
  );
};
